package cn.wzy.controller;



import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Menu;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.MenuService;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * (Menu)表控制层
 *
 * @author makejava
 * @since 2022-12-08 13:53:15
 */
@RestController
@RequestMapping("/Menu")
@AnPermission(name = "菜单管理",descs = "对菜单资源管理")
@Api(value = "菜单")
public class MenuController {
    /**
     * 服务对象
     */
    @Resource
    private MenuService menuService;


    /*
    * 分页查询
    * */
    @PostMapping("/page")
    @AnPermission(name = "菜单分页高级查询")
    @ApiOperation(value = "菜单分页")
    public ResponseResult menuPage(@RequestBody GoPageVo goPageVo){
        return menuService.menuPage(goPageVo);
    }

    /*
    * 单个删除
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "菜单id删除")
    @ApiOperation(value = "菜单单个删除")
    public ResponseResult deleteMenu(@PathVariable("id") Long id){
        return menuService.deleteMenu(id);
    }

    /*
    * 批量删除
    * */
    @PatchMapping
    @AnPermission(name = "菜单批量删除")
    @ApiOperation(value = "批量删除")
    public ResponseResult deleteListMenu(@RequestBody List<Long> ids){
        return menuService.deleteListMenu(ids);
    }


    /*
    * 添加/修改菜单
    * */
    @PostMapping
    @AnPermission(name = "菜单添加或者修改")
    @ApiOperation(value = "添加/修改菜单")
    public ResponseResult saveMenu(@RequestBody Menu menu){
        return menuService.saveMenu(menu);
    }


    /*
    * 多级菜单
    * */
    @GetMapping("/Level")
    @AnPermission(name = "多级菜单")
    @ApiOperation(value = "多级菜单")
    public ResponseResult getMenuLevel(){
        return menuService.getMenuLevel();
    }

    /*
    * 查询所有菜单的id
    * */
    @GetMapping("/allId")
    @AnPermission(name ="查询所有菜单id")
    @ApiOperation(value = "查询所有菜单id")
    public ResponseResult getALlMenuIds(){
        return menuService.getAllMenuIds();
    }

    /*
    * 通过empId动态获取对应的菜单
    * */
    @PostMapping("/dynamicPage")
    @AnPermission(name = "通过EmpId动态查询菜单分页")
    @ApiOperation(value = "通过EmpId动态查询菜单分页")
    public ResponseResult  dynamicPageMenu(@RequestBody GoPageVo goPageVo, HttpServletRequest request){
        return menuService.dynamicPageMenu(goPageVo,request);
    }


}

